import axios from 'axios';
axios.interceptors.request.use(config => {
    // token
    const token = window.localStorage.getItem('token')
    if (token) {
        config.header.token = token
    }
    return {
        config
    }
})

axios.interceptors.response.use(response => {
    return response.data;
}, err => {
    switch (err.response.status) {
        case 401:
            alert('权限校验失败')
            break;
        case 403:
            alert('权限不足')
            break;
        case 404:
            alert('接口未找到')
            break;
        case 500:
            alert('服务器报错')
            break;
        default: ;
    }
    return Promise.reject(err)
})



export default axios;